package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.DealDetailsHandler;
import com.cungmua.app.model.request.DealDetailsRequest;
import com.cungmua.app.model.response.DealDetailsResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/23/14.
 */
public class DealDetailsTask extends AuthenticatedTask<DealDetailsRequest, Void, DealDetailsResponse> {
    private Context context;
    private DealDetailsHandler handler;

    public DealDetailsTask(Context context, DealDetailsHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected DealDetailsResponse doInBackground() throws RetrofitError {
        DealDetailsRequest request = params[0];

        return service.getDealDetails(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(DealDetailsResponse dealDetailsResponse) {
        handler.onDealDetails(dealDetailsResponse);
    }
}
